<template>
	<view :style="{'background-color':pageBg}" style="float: left;width: 100%;min-height: 100%;">
		<u-navbar is-back="true"  :border-bottom="false" title-color="" back-icon-color="" title="增加分类" >
		</u-navbar>
		<view class="container">
			<view class="top_box">

				<view class="container_box css-theme" :class="[cueTheme]" style="border-radius: 5px;">
					<view class="container_box_left">
						<view class="tn-icon-tag" style="font-size: 18px;"></view>
						<text>|</text>
						<input v-model="name" focus="true" type="text" placeholder="请输入分类名称" placeholder-class="placeholder_style" />
					</view>
				</view>
			
				
				<view style="float: left;width: 100%;margin-top: 40rpx;">
					<button @click="saveData()" style="border-radius: 30px;background-color:#5A9CFC ;color:white;font-weight: bolder;">保存</button>
				</view>

			</view>
		</view>
		
		<mypopup title="" :mask="false" v-model="show" height="90%" :showHeader="false" style="position: relative;">
			<view
				style="width: 60px;height: 10rpx;background-color: #ccc;position: absolute; top:5px;margin-left: 320rpx;border-radius: 20px;">
			</view>
		
			<view class="popup-content">
				<view class="input-container">
		
					<view class="contentnav">
						<view class="nav">
							<scroll-view class="tab-scroll" scroll-x="true" scroll-with-animation>
								<view class="tab-scroll_box">
									<u-grid :col="8" :border="false">
										<u-grid-item v-for=" (item,index) in colorList" :key="index"
											@tap="checkThis(item.index,item.background)">
											<view class="color_style" :style="'background-color:'+item.background">
												<text v-if="checkedIndex == item.index" class="checkmark"></text>
											</view>
										</u-grid-item>
									</u-grid>
								</view>
							</scroll-view>
						</view>
		
					</view>
				</view>
			</view>
		</mypopup>
	</view>
</template>
<script>
	var _self;
	import mypopup from '@/components/hqs-popup/hqs-popup.vue'
	import icons from '@/common/icon.js'
	export default {
		components: {
			mypopup,
		},
		data() {
			return {
				id: '',
				userId: '',
				name: '',
				remark: '',
				type: 0,
				background: '#F8BCB1',
				checkedIndex: 0,
				colorList: icons.colorList,
				show: false,
			};
		},
		destroyed(e) {
			// _self.saveData();
		},
		onLoad(options) {
			_self = this
			_self.userId = options.userId
			_self.type = options.type
			if (options.id != 0) {
				_self.id = options.id
				_self.name = options.name
				
			}

		},
		methods: {
			saveData() {
				if (_self.name == '') {
					uni.showToast({
						title: "请输入名称",
						duration: 2000,
						icon: "none"
					});
					return;
				}
				var data = {}
				if (_self.id == '') {
					data = {
						userId: _self.userId,
						name: _self.name,
						category:_self.type
					}
				} else {
					data = {
						id: _self.id,
						userId: _self.userId,
						name: _self.name,
						category:_self.type
					}
				}
				this.$api.updateTypeCommon(data).then((res) => {
					var resData = res
					if (resData.code == "200") {
						uni.navigateBack({
							delta: 1 // 默认值是1，表示返回的页面层数
						});
					} else {
						uni.showToast({
							title: '保存失败',
							duration: 2000,
							icon: 'none'
						})
					}
				})

			},
			checkThis(index, background) {
				this.checkedIndex = index
				this.background = background
			
			},
			showPopup() {
				this.show = true
			},


		}
	};
</script>

<style lang="scss">
	page {
		height: 100%;
		width: 100%;
		margin: 0;
		background-color: $page-bg !important;
	}

	.css-theme {
		@include text-color();
		@include base-background();
		@include border-color();
		@include shadow-color();
	}

	.container {
		padding: 20rpx;
		width: 94%;
		float: left;
		margin-left: 3%;
		margin-top: 20rpx;
		/* background-color: #ffffff; */
		border-radius: 5px;


	}

	.top_box {
		float: left;
		width: 100%;

	}

	.input-container {
		display: flex;
		align-items: center;
		margin-bottom: 20px;
	}

	.label {
		width: 100px;
		font-size: 16px;
	}


	.textarea-container {
		display: flex;
		flex-direction: column;
		// border: 1px solid #f1f1f1;
		border-radius: 5px;
	}

	.textarea {
		height: 120px;

		border-radius: 5px;
		padding: 10px;
		font-size: 16px;
		width: 100%;
	}

	.fixed-image {
		position: fixed;
		right: 20px;
		/* 可根据需要调整位置 */
		bottom: 20px;
		/* 可根据需要调整位置 */
		display: flex;
		align-items: flex-end;
		justify-content: flex-end;
	}

	.fixed-image image {
		width: 80rpx;
		height: 80rpx;
	}



	.container_box {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30rpx 20rpx;
		// border: 1px solid #f1f1f1;
		margin: 16rpx 0rpx;
		border-radius: 8px;
		line-height: 25px;
		font-size: 18px;
		color: #56555B;
	}

	.container_box_left {
		display: flex;
		align-items: center;
		float: left;
		width: 100%;
	}

	.container_box_left input {
		width: 100%;
		float: left;
	}

	.container_box_left image {
		width: 20px;
		height: 20px;
	}

	.container_box_left text {
		color: #f1f1f1;
		margin-left: 20rpx;
		margin-right: 20rpx;
	}

	.placeholder_style {
		color: #ccc;
		font-size: 14px;
	}

	.container_box_top {
		justify-content: space-between;
		align-items: center;
		text-align: center;
		position: relative;
		z-index: 0;

	}

	.placeholder_style {
		color: #ccc;
		font-size: 14px;
	}


	.uploadImage_show {
		position: absolute;
		z-index: -1;
		left: 0;
		right: 0;
		bottom: 0;
		right: 0;
		width: 100%;
		height: 100%;


	}

	.uploadImage {
		width: 40px;
		height: 40px;
	}

	.view_desc {
		width: 100%;
		text-align: center;
	}

	.view_class {
		margin-left: calc(50% - 40px);
		font-size: 14px;
		color: #ccc;


	}
	.checkedIcon {
		width: 50rpx;
		height: 50rpx;
		border-radius: 50%;
		// background-color: #f7f7f7;
		line-height: 50rpx;
		text-align: right;
		font-size: 20px;
		// display: inline-block;
		margin: auto 0;
		float: right;
	}
	.popup-content {
		padding: 60rpx 20rpx;
	}
	
	.input-container {
		display: flex;
		align-items: center;
		color: #000;
	}
	.contentnav {
		display: flex;
		flex-direction: column;
		width: 100%;
		flex: 1;
		float: left;
	
		.nav {
			// border-top: 1rpx solid #f2f2f2;
			// position: fixed;
			z-index: 99;
			width: 100%;
			align-items: center;
			// height: 100rpx;
	
			.tab-scroll {
				flex: 1;
				overflow: hidden;
	
				.tab-scroll_box {
					display: flex;
					align-items: center;
					flex-wrap: nowrap;
					box-sizing: border-box;
	
					.tab-scroll_item {
						// line-height: 60rpx;
						// margin-right: 35rpx;
						flex-shrink: 0;
						// padding-bottom:10px;
						display: flex;
						justify-content: center;
						// font-size: 16px;
						// padding-top: 10px;
						// border-radius: 20rpx;
						// background-color: #12BA7D;
						// padding: 0px 10px;
						font-size: 14px;
						height: 42rpx;
						line-height: 42rpx;
						color: white;
						margin-right: 10px;
						margin-bottom: 10px;
					}
				}
			}
		}
	
		.swiper-content {
			padding-top: 90rpx;
			flex: 1;
	
			.swiperitem-content {
				background-color: $page-bg;
	
				.nav_item {
					background-color:$page-bg
					// padding:20rpx 40rpx 0rpx 40rpx ;
				}
			}
		}
	}
	
	.color_style {
		height: 50rpx;
		width: 50rpx;
		border-radius: 50%;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	
	.checkmark {
		width: 24rpx;
		height: 24rpx;
		border-radius: 50%;
		background-color: white;
	
	}
</style>